package service.impl;

import dao.AccountDao;
import entity.Account;
import service.AccountService;
public class AccountServiceImpl implements AccountService {
    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    public Account findAccountByid(Integer id) {
        return accountDao.findAccountByID(id);
    }

    @Override
    public void transfer(String sourceName, String targetName, Float money) {
        //转出的用户
        Account source=  accountDao.findAccountByName(sourceName);
        //转入的用户
        Account target=accountDao.findAccountByName(targetName);
        //3.转出钱
        source.setMoney(source.getMoney()-money);
        //4.转入钱
        target.setMoney(target.getMoney()+money);
        //5.更新
        //转出账户更新
        accountDao.updateAccount(source);
        //转入账户更新
        accountDao.updateAccount(target);
    }
}
